package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.TestBank;
import com.woniuxy.service.TestBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (TestBank)表题库控制层
 *
 * @author zjx
 * @since 2021-05-14 19:42:03
 */
@RestController
@RequestMapping("testBank")
@Api
public class TestBankController {
    /**
     * 服务对象
     */
    @Resource
    private TestBankService testBankService;

//    public ResponseEntity


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "通过id查询单条数据")
    @GetMapping("selectOne")
    public ResponseEntity selectOne(@ApiParam("题库id") Integer id) {
        return new ResponseEntity(200,"更新成功",this.testBankService.queryById(id));
    }


    /**
     * 新增一条数据
     * Auther: zjx  <br/>
     * Date: 2021/5/15:11:30  <br/>
     * Description:
     */
    @PostMapping("/insert")
    @ApiOperation(value = "插入一条数据",notes = "根据添加的对象插入数据")
    public ResponseEntity insert(@ApiParam("题库对象")@RequestBody TestBank testBank){
        System.out.println(testBank+"testBank============");
        return new ResponseEntity(200,"OK",testBankService.insert(testBank));
    }

    /**
     * Description : 试题库首页分页查询展示
     * ChangeLog : 1. 创建 (2021/5/15 15:18 [zjx]);
     * @param map 起始页，每页条数，题库对象
     * @return 分页数据
    */
    @ApiOperation(value = "分页查询")
    @PostMapping("/queryAll")
    public ResponseEntity queryAll(@ApiParam("起始页，每页条数，题库对象") @RequestBody Map<String,Object> map){
//        System.out.println(map+"输入数据===========");
        return new ResponseEntity(200,"成功",this.testBankService.queryAll(map));
    }
    /**
     * 更新一条数据
     * Auther: zjx  <br/>
     * Date: 2021/5/15:11:39  <br/>
     * Description:
     */
    @ApiOperation(value = "更新一条数据")
    @PutMapping("/update")
    public ResponseEntity update(@ApiParam("题库对象") @RequestBody TestBank testBank){
        return new ResponseEntity(200,"成功",this.testBankService.update(testBank));
    }
    /**
     * 根据主键删除一条数据
     * Auther: zjx  <br/>
     * Date: 2021/5/15:11:40  <br/>
     * Description:
     */
    @ApiOperation(value = "通过id删除单条数据")
    @DeleteMapping("/deleteById/{testBankId}")
    public ResponseEntity deleteById(@ApiParam("题库id") @PathVariable Integer testBankId){
        return new ResponseEntity(200,"OK",this.testBankService.deleteById(testBankId));
    }


}
